<!DOCTYPE html>
<html class="x-admin-sm">
    <head>
        <meta charset="UTF-8">
        <title>授权</title>
        <meta name="renderer" content="webkit">
        <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
        <link rel="stylesheet" href="/oauthplatform/static/css/x-admin/font.css">
        <link rel="stylesheet" href="/oauthplatform/static/css/x-admin/xadmin.css">
        <link rel="stylesheet" href="/oauthplatform/static/lib/zTree/css/zTreeStyle/zTreeStyle.css">
    </head>

    <body>
        <div class="layui-fluid layui-row layui-col-space15">
            <div class="layui-col-sm12 layui-col-md12">
                <div class="layui-card">
                    <div class="layui-card-header">角色 : ${roleInfo.name}
                        <a class="layui-btn layui-btn-small" style="line-height:1.6em;margin-top:3px;float:right" onclick="saveInfo()" title="保存">
                            <i class="layui-icon" style="line-height:30px">&#xe605;</i>
                        </a>
                    </div>

                    <div class="layui-card-body">
                        <div id="treeDiv" class="ztree"></div>
                    </div>
                </div>
            </div>
        </div>
        <input type="hidden" value="${(roleInfo.id?c)!}" id="rid">
    </body>
    <script type="text/javascript" src="/oauthplatform/static/lib/jquery/jquery.3.4.1.js"></script>
    <script src="/oauthplatform/static/lib/layui/layui.js" charset="utf-8"></script>
    <script src="/oauthplatform/static/lib/other/html5.min.js"></script>
    <script src="/oauthplatform/static/lib/other/respond.min.js"></script>
    <script src="/oauthplatform/static/lib/zTree/js/jquery.ztree.all.js"></script>
    <script src="/oauthplatform/static/lib/x-admin/xadmin.js"></script>
    <script type="application/javascript">

        $(function(){
            loadTree();
        })

        var treeObj;
        function loadTree(){
            var setting = {
                async:{
                    enable : true,
                    url : '/oauthplatform/authorization/tree',
                    type : "post",
                    otherParam:{rid:$("#rid").val()}
                },
                data:{
                    simpleData:{
                        enable : true,
                        idKey : "id",
                        pIdKey : "pid"
                    }
                },
                check:{
                    enable:true,
                    chkStyle:"checkbox",
                    chkboxType : { "Y" : "", "N" : "" }
                }
            };
            treeObj = $.fn.zTree.init($("#treeDiv"), setting);
        }


        function saveInfo(){
            var nodes = treeObj.getCheckedNodes(true);
            var ids = "";
            if(nodes != null && nodes.length > 0){
                for(var i = 0;i<nodes.length;i++){
                    var node = nodes[i];
                    ids += node.id + ",";
                }
            }
            var rid = $("#rid").val();
            if(rid==null||rid==''){
                layer.msg("参数异常,请联系管理员");
                return false;
            }
            $.ajax({
                type: "POST",//方法类型
                url: "/oauthplatform/authorization/save" ,//url
                data: {rid:rid,pids:ids},
                success: function (result) {
                    layer.msg(result.msg);
                    if(parseInt(result.code) == 200){
                        setTimeout(function(){ location.reload(); }, 900);
                    }
                },
                error: function (result) {
                    layer.msg("系统异常,请联系管理员");
                }
            });
        }
    </script>
</html>
